import { DriverCommand } from './driver-command';
import { DriverParseOptions } from '../type';
import { Command, CommandBuilder } from '$domain/service/commandBuilder';

export class DriverParseCommand extends DriverCommand {

  private modelDir: string;
  private modelEntry: string;
  private outputFilePath: string;

  constructor(options: DriverParseOptions) {
    super(options.driverName, options.logger);
    this.modelDir = options.modelDir;
    this.modelEntry = options.modelEntry;
    this.outputFilePath = options.outputFilePath;
  }

  private generateCommandOptions() {
    const commandOption = {
      '-m': this.modelDir,
      '-o': this.outputFilePath,
      '-d': this._driver.driverConfigPath
    };

    if (this.modelEntry) {
      commandOption['-e'] = this.modelEntry;
    }
    return commandOption;
  }

  protected buildCommand(): Command {
    return new CommandBuilder()
      .setExecutable(this._driver.executable)
      .setCommand('parse')
      .setOptions(this.generateCommandOptions())
      .build();
  }
}
